<?php

namespace app\index\controller;

use think\Request;

class Template {
	private $transcodeCreatePath = "/template/transcode/create";
	private $transcodeSearchPath = "/template/transcode/search";
	private $transcodeGetPath = "/template/transcode/get";
	private $transcodeDeletePath = "/template/transcode/delete";
	
	private $watermarkCreatePath = "/template/watermark/create";
	private $watermarkCompletePath = "/template/watermark/create/complete";
	private $watermarkSearchPath = "/template/watermark/search";
	private $watermarkGetPath = "/template/watermark/get";
	private $watermarkDeletePath = "/template/watermark/delete";
	
	// 创建一个转码模板
	public function createTranscodeTemplate(Request $request) {
		return \VodClient::execute ( json_encode ( $request->post () ), $this->transcodeCreatePath );
	}
	
	// 搜索转码模板
	public function searchTranscodeTemplate(Request $request) {
		return \VodClient::execute ( json_encode ( $request->post () ), $this->transcodeSearchPath );
	}
	
	// 获取单个转码模板
	public function getTranscodeTemplate(Request $request) {
		return \VodClient::execute ( json_encode ( $request->post () ), $this->transcodeGetPath );
	}
	
	// 删除转码模板
	public function deleteTranscodeTemplate(Request $request) {
		return \VodClient::execute ( json_encode ( $request->post () ), $this->transcodeDeletePath );
	}
	
	// 创建水印模板
	public function createWatermarkTemplate(Request $request) {
		return \VodClient::execute ( json_encode ( $request->post () ), $this->watermarkCreatePath );
	}
	
	// 上传水印图片
	public function uploadWatermarkPicture(Request $request) {
		// todo
		$presignedUrl = $request->param ( "presignedUrl" );
		$filePath = $request->param ( "filePath" );
		$res = \CommonUtil::isLegalPicture ( $filePath );
		if ($res == false) {
			$rsp = array (
					'code' => "1",
					'message' => "传入的水印图片不是PNG格式或者大小超过5M，请检查" 
			);
			return $rsp;
		}
		// 上传文件
		$file = file ( $filePath );
		\CommonUtil::upload ( $presignedUrl, $file );
	}
	
	// 完成水印图片上传
	public function completeWatermarkTemplate(Request $request) {
		return \VodClient::execute ( json_encode ( $request->post () ), $this->watermarkCompletePath );
	}
	
	// 搜索水印模板
	public function searchWatermarkTemplate(Request $request) {
		return \VodClient::execute ( json_encode ( $request->post () ), $this->watermarkSearchPath );
	}
	
	// 获取单个水印模板
	public function getWatermarkTemplate(Request $request) {
		return \VodClient::execute ( json_encode ( $request->post () ), $this->watermarkGetPath );
	}
	
	// 删除水印模板
	public function deleteWatermarkTemplate(Request $request) {
		return \VodClient::execute ( json_encode ( $request->post () ), $this->watermarkDeletePath );
	}
}
